﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Entity;
using BLL;
using BLL.Access;
using System.Data;
using Platform.Http;
using Web.Class;
using System.IO;
using System.Data.Odbc;
using System.Data.OleDb;
using DevExpress.Web;

namespace Web.Pages.QuShui.DiXiaS._8.QiTaGL
{
   


    public partial class TeShuYH : BasePage
    {
        #region  属性
    
        #endregion

        #region 变量
        SpHelper sphelper = new SpHelper();
        #endregion

        #region 事件
        
       
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Bind();
            }
        }
        protected void gvList_FocusedRowChanged(object sender, EventArgs e)
        {
            string[] para = new string[2];
            para[0] = "S_YONGHUH";
            para[1] = "S_YONGHUM";
            object o= gvList.GetRowValues(gvList.FocusedRowIndex, para);
            
            BindYONGHUH(o);
        }
        protected void BtnSearch_Click(object sender, EventArgs e)
        {
            Bind();
        }
        protected void CallBackControl_Callback(object source, CallbackEventArgs e)
        {
            if (e.Parameter == "select")
            {
                string[] para = new string[2];
                para[0] = "S_YONGHUH";
                para[1] = "S_YONGHUM";
                object o = gvList.GetRowValues(gvList.FocusedRowIndex, para);
                object[] yonghu = o as object[];
                e.Result = e.Parameter + "|1|成功|" + yonghu[0] + "|" + yonghu[1];
            }
            if (e.Parameter == "del")
            {
                string[] para = new string[2];
                para[0] = "S_YONGHUH";
                para[1] = "S_YONGHUM";
                object o = gvList.GetRowValues(gvList.FocusedRowIndex, para);
                object[] yonghu = o as object[];
                DataSet ds = sphelper.P_QS_QT_TESHUYH(2, yonghu[0].ToString(), LoginInfo.CurrentUser.Account);
                e.Result = e.Parameter + "|" + ds.Tables[0].Rows[0][0] + "|成功|" + yonghu[0] + "|" + yonghu[1];
            }
            if (e.Parameter == "save")
            {
                DataSet ds = sphelper.P_QS_QT_TESHUYH(3, txtYongHuH.Text.Trim(), "");
                int code = 0;
                if (ds.Tables[0].Rows.Count > 0)
                {
                    code = 1;
                }
                else
                {
                    code = -1;
                }
                ds = sphelper.P_QS_QT_TESHUYH(4, txtYongHuH.Text.Trim(), "");

                if (ds.Tables[0].Rows.Count > 0)
                {
                    code = -3;
                }
                else
                {
                    code = 1;
                }
                if (code > 0)
                {
                    DataSet newds = sphelper.P_QS_QT_TESHUYH(1, txtYongHuH.Text.Trim(), LoginInfo.CurrentUser.Account);
                    if (newds.Tables[0].Rows.Count > 0)
                    {
                        code = 1;
                    }
                    else
                    {
                        code = -2;
                    }
                }
                e.Result = e.Parameter + "|" + code + "|成功|";
            }
        }
        #endregion


        #region 方法

        private void Bind()
        {
            DataSet ds = sphelper.P_QS_QT_TESHUYH(0,"","");
            gvList.DataSource = ds.Tables[0];
            gvList.DataBind();
            gvList.FocusedRowIndex = -1;
            gvList.FocusedRowIndex = 0;
        }

        private void BindYONGHUH(object yonghu)
        {
            if (yonghu == null)
            {
                return;
            }
           object[] o=yonghu as object[];
           
           
            txtYongHuH.Text = o[0].ToString();
            txtYongHuM.Text = o[1].ToString();

        }

        #endregion

        

       

        
    }
}